#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

struct arc
{
	int end;
	int l;
};

typedef vector<arc> va;
typedef vector<va> vva;

	vva g;
	int best;
	int mark[10010];
	
int find_ans(int v, int len)
{
	int f = 0, s = -1;
	int fv = v, sv;
	int i, k, y;
	int nn;
	
	mark[v] = 1;
	
	nn = g[v].size();
	for (i=0; i<nn; i++)
	{
		y = g[v][i].end;
		if (mark[y] == 0)
		{
			k = find_ans(y, len+g[v][i].l) + g[v][i].l;
			if (k > f)
			{
				s = f; f = k;
				sv = fv; fv = y;
			}else 
			if (k > s)
			{
				s = k;
				sv = y;
			}
		}
	}
	if (len + f > best) best = len + f;
	if (f + s > best) best = f + s;
	mark[v] = 0;
	
	return f;
}

main()
{
	arc tmp;
	int i, j, k;
	int x, y, l;
	
	g.clear();
	g.resize(10010);
	memset(mark, 0, sizeof(mark));
	
	//freopen("h.in", "r", stdin);
	//freopen("h.out", "w", stdout);
	
	while (scanf("%ld%ld%ld", &x, &y, &l)!=EOF)
	{
		tmp.end = y; tmp.l = l; g[x].push_back(tmp);
		tmp.end = x; tmp.l = l; g[y].push_back(tmp);
	}
	best = -1;
	find_ans(1, 0);
	
	printf("%ld\n", best);
	return 0;
}

